package cn.wit.summit.chwan.widgets;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import cn.wit.summit.chwan.R;

/**
 * Created by pengsk on 2018/4/22.
 */

public class NoticeDialog extends Dialog implements View.OnClickListener {
    private OnClickButnInterface onClickButnInterface;

    protected NoticeDialog(Context context) {
        super(context);
    }

    public NoticeDialog(Context context, int theme) {
        super(context, theme);
    }

    public NoticeDialog setOnClickButnInterface(OnClickButnInterface onClickButnInterface) {
        this.onClickButnInterface = onClickButnInterface;
        return this;
    }

    String titleTx;
    String contentTx;

    public NoticeDialog setData(String titleTx, String contentTx) {
        if (title != null)
            title.setText(titleTx);
        if (content != null)
            content.setText(contentTx);

        this.titleTx = titleTx;
        this.contentTx = contentTx;
        return this;
    }

    TextView title;
    TextView content;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notice_dialog_layout);
        title = findViewById(R.id.title);
        content = findViewById(R.id.content);
        title.setText(titleTx);
        content.setText(contentTx);
        TextView cancleButn = findViewById(R.id.cancleButn);
        TextView okButn = findViewById(R.id.okButn);
        cancleButn.setOnClickListener(this);
        okButn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.cancleButn:
                onClickButnInterface.onClickCancleButn(this);
                break;
            case R.id.okButn:
                onClickButnInterface.onClickOkButn(this);
                break;
        }
    }

    public interface OnClickButnInterface {
        public void onClickCancleButn(NoticeDialog noticeDialog);

        public void onClickOkButn(NoticeDialog noticeDialog);

    }
}
